package org.spring.springboot.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.spring.springboot.entity.VisitorSubscribeCommit;
import org.spring.springboot.entity.VisitorTeg;
import org.spring.springboot.result.R;
import org.spring.springboot.result.Result;
import org.spring.springboot.server.VisitorSubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;


@RestController
@Api(tags = "访客预约")
@RequestMapping("/visitorSubscribe")
public class VisitorSubscribeController {

    @Autowired
    private VisitorSubscribeService visitorSubscribeService;

    @ApiOperation("新增预约")
    @PostMapping("/addInterview")
    public Result addInterview(@RequestBody VisitorSubscribeCommit vs){
        visitorSubscribeService.addSubscribe(vs);
        return Result.newSuccessResult(vs);
    }
    @ApiOperation("新增预约同行")
    @PostMapping("/addIntervwiewTeg")
    public Result addInterviewTeg(@RequestBody VisitorTeg vt){
        int id = visitorSubscribeService.selectId();
        vt.setFid(id);
        visitorSubscribeService.addSubscribeTeg(vt);
        return Result.newSuccessResult(vt);
    }

    @PostMapping("/updateIntervieweeId")
    @ApiOperation("被访者审批")
    public Result updateIntervieweeId(@RequestParam(value = "intervieweeId") Integer intervieweeId,
                                      @RequestParam(value = "id") Integer id,
                                      @RequestParam(value = "remark1") String remark1){
        visitorSubscribeService.interviewee_manage(intervieweeId, id ,remark1);
        return Result.newSuccessResult("intervieweeId:"+intervieweeId+" id:"+id+" remark1:"+remark1);
    }

    @PostMapping("/updateDepartmentId")
    @ApiOperation("部门经理审批")
    public Result updateDepartmentId(@RequestParam(value = "departmentId") Integer departmentId,
                                     @RequestParam(value = "departmentName") String departmentName,
                                     @RequestParam(value = "id") Integer id,
                                     @RequestParam(value = "remark2") String remark2){
        visitorSubscribeService.department_manage(departmentId, departmentName, id, remark2);
        return Result.newSuccessResult("departmentId:"+departmentId+" departmentName"+departmentName+" id:"+id+" remark2:"+remark2);
    }

    @PostMapping("/updateComplete")

    @ApiOperation("给1预约完成访问")
    public Result updateComplete(@RequestParam(value = "complete") Integer complete,
                                 @RequestParam(value = "id") Integer id){
        visitorSubscribeService.subscribe_complete(complete,id);
        return Result.newSuccessResult("id:"+id+" complete"+complete);
    }

    @PostMapping("/selectInviteMsg")
    @ApiOperation("访客信息")
    public Result selectInviteMsg(Integer id){
        return Result.newSuccessResult(visitorSubscribeService.selectByExitlist(id));
    }

    @PostMapping("/selectHistory")
    @ApiOperation("预约历史记录")
    public R selectHistory(@RequestParam("starttime") Timestamp starttime,
                           @RequestParam("endtime") Timestamp endtime,
                           @RequestParam("id") Integer id,
                           @RequestParam("pagenum") Integer pagenum,
                           @RequestParam("pagesize") Integer pagesize){
        Page page = PageHelper.startPage(pagenum, pagesize);
        List<Map<String, Object>> maps = visitorSubscribeService.selectByRecord(starttime, endtime,id);
        Long total = page.getTotal();
        return R.newSuccessResult(maps,total);
    }

    @PostMapping("/selectIntervieweeName1")
    @ApiOperation("查询被访者姓名(<=1)")
    public List<Map<String, Object>> selectIntervieweeName1(String name){
        return visitorSubscribeService.intervieweeName1(name);
    }

    @PostMapping("/selectIntervieweeName2")
    @ApiOperation("查询被访者姓名(>1)")
    public List<Map<String, Object>> selectIntervieweeName2(String name,String mobile){
        return visitorSubscribeService.intervieweeName2(name,mobile);
    }

    @PostMapping("/selectSubscribe")
    @ApiOperation("查询预约审批状态")
    public List<Map<String, Object>> selectSubscribe(String visitorname){
        return visitorSubscribeService.selectSubscribeStatus(visitorname);
    }

    @PostMapping("/selectVisitorMsg")
    @ApiOperation("同行信息")
    public Result selectVisitorTeg(Integer fid){
        return Result.newSuccessResult(visitorSubscribeService.selectVisitorByFid(fid));
    }

}
